#include <iostream>

using namespace std;

/*
 * 利用函数模板封装一个排序的函数，可以对不同数据类型数组进行排序
 *  规则：由大到小
 */

template<class T>
void selectSort(T arr[], int length){
    for (int i = 0; i < length-1; ++i) {
        int index = i;
        for (int j = i+1; j < length; ++j) {
            if(arr[j]>arr[index]){
                index = j;
            }
        }
        if(index != i){
            T temp = arr[index];
            arr[index] = arr[i];
            arr[i] = temp;
        }
    }
}

void test01(){
    int arr[10] = {1,2,3,4,5,6,7,8,9,10};
    selectSort(arr, 10);
    for (int i = 0; i < 10; ++i) {
        cout << i << "=" << arr[i] << endl;
    }

    char arr2[10] = {'g', 'h', 'a', 'b', 'c', 'd', 'e', 'f', 'm', 'z'};
    selectSort(arr2, 10);
    for (int i = 0; i < 10; ++i) {
        cout << i << "=" << arr2[i] << endl;
    }
}

int main() {

    test01();

    return 0;
}
